package controllers

import (
	"net/http"

	"github.com/labstack/echo"
)

type Api struct {
	Router  *echo.Echo
	Context echo.Context
}

func (this *Api) Resp() {
}

func (this *Api) Success(data interface{}, errmsg string) interface{} {
	type ApiResp struct {
		Errno  int         `json:"errno"`
		Errmsg string      `json:"errmsg"`
		Data   interface{} `json:"data"`
	}
	r := new(ApiResp)
	r.Errno = 0
	r.Errmsg = errmsg
	return this.Context.JSON(http.StatusOK, r)
}

func (this *Api) Fail(errno int, errmsg string) error {
	type ApiResp struct {
		Errno  int    `json:"errno"`
		Errmsg string `json:"errmsg"`
		//Data   interface{} `json:"data"`
	}
	r := new(ApiResp)
	r.Errno = errno
	r.Errmsg = errmsg
	return this.Context.JSON(http.StatusOK, r)
}
